package com.jackchong.ext

import java.lang.StringBuilder

/**
 * author : chong.huang
* create : 2021/6/6
 * desc   :
 */

fun String.deleteAt(index: Int): String = StringBuilder(this).deleteCharAt(index).toString()

fun String.deleteLast(): String = if (this.isEmpty()) this else StringBuilder(this).deleteCharAt(this.length - 1).toString()

inline fun <T> Iterable<T>.sumByStr(selector: (T) -> String): String {
    var sum = ""
    for (element in this) {
        sum += selector(element)
    }
    return sum
}

/**
 * author  : chong.huang
 * time    : 8/7/21 11:31 AM
 * desc    : 逗号提取
 */
inline fun  <T> Iterable<T>.extractComma(selector: (T) -> String): String {
    var sum = ""
    for (element in this) {
        sum = sum + selector(element) + ","
    }
    return sum.deleteLast()
}